//
//  PickUpAddressViewController.m
//  Hui
//
//  Created by HawkingWang on 16/10/27.
//  Copyright © 2016年 Hui. All rights reserved.
//

#import "PickUpAddressViewController.h"
#import "LocationViewController.h"//地图Controller

@interface PickUpAddressViewController () <UITextFieldDelegate, UITextViewDelegate>
/**取货人姓名*/
@property (weak, nonatomic) IBOutlet UITextField *name;
/**选择性别*/
@property (weak, nonatomic) IBOutlet UIImageView *maleImage;
@property (weak, nonatomic) IBOutlet UIImageView *femaleImage;
/**取货人电话*/
@property (weak, nonatomic) IBOutlet UITextField *phone;
/**取货地址*/
@property (weak, nonatomic) IBOutlet UILabel *address;
/**详细地址*/
@property (weak, nonatomic) IBOutlet UITextView *detailAddress;
@property (weak, nonatomic) IBOutlet UILabel *detailLabel;

@end

@implementation PickUpAddressViewController
{
    NSString *_sex;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    self.navigationController.navigationBar.hidden = YES;
    _detailAddress.delegate = self;
    _name.delegate = self;
}
#pragma mark === 性别选择 ===
- (IBAction)chooseMale:(id)sender {
    _sex = @"0";
    _maleImage.image = [UIImage imageNamed:@"right-touch"];
    _femaleImage.image = [UIImage imageNamed:@"right"];
}
- (IBAction)chooseFemale:(id)sender {
    _sex = @"1";
    _maleImage.image = [UIImage imageNamed:@"right"];
    _femaleImage.image = [UIImage imageNamed:@"right-touch"];
}
#pragma mark === 跳转到地图界面 ===
- (IBAction)jumoToMap:(id)sender {
    LocationViewController *location = [[LocationViewController alloc] init];
    [self.navigationController pushViewController:location animated:YES];
}

#pragma mark === 提交 ===
- (IBAction)commit:(id)sender {
    if ([_name.text isEqualToString:@""]) {
        [EBUtility prompt:@"请输入联系人姓名" with:self];
        return;
    }
    if ([_phone.text isEqualToString:@""]) {
        [EBUtility prompt:@"请输入联系方式" with:self];
        return;
    }
    if (![EBUtility isMobileNumber:_phone.text]) {
        [EBUtility prompt:@"请输入正确的联系方式" with:self];
    }
    if ([_detailAddress.text isEqualToString:@""]) {
        [EBUtility prompt:@"请输入详细地址" with:self];
        return;
    }
}

#pragma mark === UITextFieldDelegate ===
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    _detailLabel.hidden = YES;
    return YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView{
    if ([_detailAddress.text isEqualToString:@""]) {
        _detailLabel.hidden = NO;
    }
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [_name resignFirstResponder];
    [_phone resignFirstResponder];
    [_address resignFirstResponder];
    [_detailAddress resignFirstResponder];
}
- (IBAction)back:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
